home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / progjour / 1989 / 05 / oop.cls < prev    next >
Text File  |  1989-07-03  |  4KB  |  195 lines

  1. //
  2. //    OOP.CLS - Methods for two way linked lists
  3. //
  4.  
  5. Include "Root.cls"
  6.  
  7.  
  8.  
  9.  
  10.  
  11. // -----------------------------------------------------------------
  12. // ------------Class TwllHead---------------------------------------
  13. // -----------------------------------------------------------------
  14.  
  15. Class TwllHead : ObjRoot{
  16.     Obj     top;
  17.     int     cnt;
  18.     }
  19. Methods:
  20.  
  21. // -----------------------------------------------------------------
  22. // Add a new twll item to a list
  23. //
  24.  
  25. AddItem(Twll_s *twll)
  26.     {
  27.         struct Twll_s *cur;
  28.  
  29.         cur        =self->top;
  30.         twll->prev =0;
  31.         twll->next =cur;
  32.         if (cur) {
  33.             cur->prev  =twll;
  34.             self->top  =twll;
  35.             self->cnt++;
  36.             }
  37.         self->top=twll;
  38.         return;
  39.     }
  40.  
  41. // -----------------------------------------------------------------
  42. // This method passes a message on to all the Objects in the list.
  43. //
  44.  
  45. SendAll(int pass_msg)
  46.     {
  47.         Twll_s      *x;
  48.  
  49.         for(x=self->top; x ;x=x->next)
  50.             Send(x,pass_msg);
  51.         return;
  52.     }
  53.  
  54.  
  55.  
  56.  
  57.  
  58. // -----------------------------------------------------------------
  59. // ------------Class Twll-------------------------------------------
  60. // -----------------------------------------------------------------
  61. //
  62. //  Abstract Root class for all object that can be added to a list
  63.  
  64. Class Twll : ObjRoot {
  65.     Obj     prev;
  66.     Obj     next;
  67.     }
  68.  
  69.  
  70.  
  71.  
  72.  
  73. // -----------------------------------------------------------------
  74. // ------------Class DataTwll---------------------------------------
  75. // -----------------------------------------------------------------
  76.  
  77. Class DataTwll : Twll {
  78.     int     x, y;
  79.     }
  80.  
  81. Methods:
  82.  
  83. // -----------------------------------------------------------------
  84. // Initialize a DataTwll object for x and y
  85. //
  86.  
  87. int ObjInit()
  88.     {       // init x and y
  89.         self->x=5;
  90.         self->y=6;
  91.         SendSuper(SuperDataTwll,msg);           /* pass the init msg up */
  92.         return;
  93.     }
  94.  
  95.  
  96. // -----------------------------------------------------------------
  97. // Set the value of X
  98. //
  99.  
  100. SetX(int x)
  101.     {
  102.         self->x=x;
  103.     }
  104.  
  105.  
  106. // -----------------------------------------------------------------
  107. // Print the contents of a data TWLL
  108. //
  109.  
  110. Print()
  111.     {
  112.         printf("x is %d, y is %d \t",self->x,self->y);
  113.         Send(self,ObjPrintName);
  114.     }
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121. // -----------------------------------------------------------------
  122. // ------------Class MyDataTwll-------------------------------------
  123. // -----------------------------------------------------------------
  124.  
  125. Class MyDataTwll : DataTwll {
  126.     char    a[10], b[10];
  127.     }
  128.  
  129. Methods:
  130.  
  131. // -----------------------------------------------------------------
  132. // Print the contents of a MyDataTwll
  133. //
  134.  
  135. Print()
  136.     {
  137.         printf("a is %s \t",self->a);
  138.         SendSuper(SuperMyDataTwll,msg);
  139.     }
  140.  
  141. // -----------------------------------------------------------------
  142. // Set the value of a
  143. //
  144.  
  145. SetA(char *str) { strcpy(self->a,str); }
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152. // -----------------------------------------------------------------
  153. // ------------Class OtherDataTwll----------------------------------
  154. // -----------------------------------------------------------------
  155.  
  156. Class OtherDataTwll : DataTwll {
  157.     int     a;
  158.     }
  159.  
  160. Methods:
  161.  
  162. // -----------------------------------------------------------------
  163. // Print the contents of an OtherDataTwll
  164. //
  165.  
  166. Print()
  167.     {
  168.         printf("a is %d \t",self->a);
  169.         SendSuper(SuperMyDataTwll,msg);
  170.     }
  171.  
  172. // -----------------------------------------------------------------
  173. // Set the value of a
  174. //
  175.  
  176. SetA(int a)
  177.     {
  178.         self->a=a;
  179.     }
  180.  
  181.  
  182.  
  183.  
  184. // -----------------------------------------------------------------
  185. // -----------------------------------------------------------------
  186. OtherCode {
  187. abort_msg(char *msg)
  188. {
  189.     puts(msg);
  190.     exit(1);
  191. }
  192.  
  193. }
  194.  
  195.